<?php
if(isset($_POST['submitsetting'])) {
	
	if(isset($_FILES['uploads']['name'])) {
		$spl_char = array(" ", "&", "|", "~", "!", "@", "#", "$", "%", "^", "*", "(", ")", "+", "=", "{", "}", ":", ";","'",'"',"<",">","?","/",",","\\");
		$news_pic_stored_name = mktime(date("H"), date("i"), date("s"), date("n"), date("j"), date("Y"))."_".str_replace($spl_char, "", $_FILES['uploads']['name']);
		move_uploaded_file($_FILES['uploads']['tmp_name'], "../uploads/".$news_pic_stored_name);
	}
	
	$res = "update site_settings set `live_status` = '".$_POST['site_status']."', `offline_message` = '".$_POST['offline_message']."', `site_url` = '".$_POST['site_url']."'";
	
	if($_FILES['uploads']['name'] != "") {
		$res .= ", `site_logo` = '".$news_pic_stored_name."'";
	}

	mysql_query($res) or die(mysql_error());
}

$res = mysql_fetch_array(mysql_query("select `live_status`, `offline_message`, `site_url`, `site_logo` from site_settings"));

$live_checked = "";
$off_checked = "";
if($res['live_status'] == "1") {
	$live_checked = "checked";
}

if($res['live_status'] == "0") {
	$off_checked = "checked";
}
?>

<div style="float: left; width: 920px; padding-top: 20px;">
<form action="" method="post" name="form1" enctype="multipart/form-data">
<div id="response"></div>
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
  <tbody><tr>
    <td valign="middle" width="4%" align="left">&nbsp;</td>
    <td valign="middle" width="20%" align="left">&nbsp;</td>
    <td valign="middle" width="4%" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5" valign="middle" align="left"><h2>Site Settings</h2></td>
    </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">
    <div id="report" style="padding: 10px; color: rgb(0, 153, 51);" class="font12">
        </div>
    </td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td class="font12" valign="middle" align="left">Site status</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" class="font12" valign="middle" align="left">
    <input name="site_status" id="radio" value="1" type="radio" <?php echo $live_checked;?>> Online
    <input name="site_status" id="radio2" value="0" type="radio" <?php echo $off_checked;?>> Offline
    </td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td class="font12" valign="middle" align="left">Offline message</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">
    <textarea id="offline_message" name="offline_message" class="txt-150" style="width: 400px; height: 100px;" cols="45" rows="5"><?php echo $res['offline_message'];?></textarea>
    </td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td class="font12" valign="middle" align="left">Site URL</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">
    <input class="txt-150" style="width: 220px;" id="site_url" name="site_url" value="<?php echo $res['site_url'];?>" type="text">
    </td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td class="font12" valign="middle" align="left">Site Logo</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">
    <input name="uploads" type="file">
    </td>
    <td rowspan="3" valign="top" width="45%" align="left">
    <?php
	if($res['site_logo'] != "") { 
		echo '<img src="../uploads/'.$res['site_logo'].'"/>';
	}
	?>
    </td>
  </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" width="27%" align="left">
      <input name="submitsetting" class="buttonbg" id="submitsetting" value="Update" type="submit">
    </td>
    </tr>
  <tr>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td valign="middle" align="left">&nbsp;</td>
    <td colspan="2" valign="middle" align="left">&nbsp;</td>
  </tr>
</tbody></table>
</form>

</div>